package com.dycc.attch_componet.view.impl;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.dycc.attch_componet.R;
import com.dycc.attch_componet.R2;
import com.dycc.attch_componet.adapter.VideoPlayerAdapter;
import com.dycc.audio_video_fcomponet.video.JCVideoPlayer;
import com.dycc.libary.base.BaseShareActivity;
import com.dycc.libary.config.CustomLinearLayoutManager;
import com.dycc.libary.http.commonbean.attach.VideoBean;
import com.dycc.libary.view.alert.AlertDialog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 视频预览
 */
@Route(path = "/attach_f/activity/VedioShowActivity", name = "图片预览")
public class VedioShowActivity extends BaseShareActivity {

    VideoPlayerAdapter adapter;

    @BindView(R2.id.edit_back_llayout)
    LinearLayout editBackLlayout;
    @BindView(R2.id.edit_rlayout)
    RelativeLayout editRlayout;
    @BindView(R2.id.vedio_show_recyclerview)
    RecyclerView vedioShowRecyclerview;
    @BindView(R2.id.vedio_show_llayout)
    LinearLayout vedioShowLlayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vedio_show);
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
    }

    String[] videoUrls = {"http://video.jiecao.fm/5/1/%E8%87%AA%E5%8F%96%E5%85%B6%E8%BE%B1.mp4",
            "http://gslb.miaopai.com/stream/ed5HCfnhovu3tyIQAiv60Q__.mp4"};
    String[] videoThumbs = {"http://img4.jiecaojingxuan.com/2016/5/1/3430ec64-e6a7-4d8e-b044-9d408e075b7c.jpg",
            "http://img4.jiecaojingxuan.com/2016/3/14/2204a578-609b-440e-8af7-a0ee17ff3aee.jpg"};

    @Override
    protected void initData() {
        VideoBean bean1 = new VideoBean();
        bean1.setTitle("测试视频1");
        bean1.setBelong("测试账号1");
        bean1.setUrl("http://video.jiecao.fm/5/1/%E8%87%AA%E5%8F%96%E5%85%B6%E8%BE%B1.mp4");
        bean1.setSmall_icon("http://img4.jiecaojingxuan.com/2016/5/1/3430ec64-e6a7-4d8e-b044-9d408e075b7c.jpg");
        VideoBean bean2 = new VideoBean();
        bean2.setTitle("测试视频2");
        bean2.setBelong("测试账号2");
        bean2.setUrl("http://gslb.miaopai.com/stream/ed5HCfnhovu3tyIQAiv60Q__.mp4");
        bean2.setSmall_icon("http://img4.jiecaojingxuan.com/2016/3/14/2204a578-609b-440e-8af7-a0ee17ff3aee.jpg");
        List<VideoBean> beans = new ArrayList<>();

        beans.add(bean1);
        beans.add(bean2);
        beans.add(bean1);
        beans.add(bean2);

        adapter = new VideoPlayerAdapter(beans, this);
        adapter.setDownloadListener(new VideoPlayerAdapter.onDownloadListener() {
            @Override
            public void onDownload(View view, VideoBean item) {
                new AlertDialog(VedioShowActivity.this).builder().setCancelable(true).setTitle("下载提示")
                        .setMsg("是否下载:" + item.getTitle() + "?")
                        .setNegativeButton("取消", null)
                        .setPositiveButton("下载", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                            }
                        }).show();
            }
        });
        adapter.setSharedListener(new VideoPlayerAdapter.onSharedListener() {
            @Override
            public void onSharedListener(View view, VideoBean item) {

            }
        });
        vedioShowRecyclerview.setLayoutManager(new CustomLinearLayoutManager(this));
        adapter.isFirstOnly(false);
        vedioShowRecyclerview.setAdapter(adapter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
    }
}
